import json

import pytest
import requests


# def csh():
#     with open("aa.json", "r", encoding="utf-8") as E:
#         return json.load(E)

class Testhelp:
    token = ""
    uid = ""
    def setup_method(self):
        print("开始")

    def teardown_method(self):
        print("清理环境")
        # 登录后新增地区，查看地区列表，启动，禁用

    # @pytest.mark.parametrize("bb", csh())
    def test_login(self):
        url = "http://10.59.9.21/api/user/login"
        body = {"username":"admin","password":"8i4De25KlVQVwqTDgTNGqw=="}
        r = requests.post(url=url, json=body)
        Testhelp.token = r.json()['token']
        print(r.json())
        assert r.status_code==200
        assert r.json()['data']['username']=='admin'
        assert 'admin' in r.text
    def test_add(self):
        url="http://10.59.9.21/api/area/add"
        body={"atype":2,"name":"综合服务平台","sort":"116"}
        headers = {"token": Testhelp.token, "uid": "1"}
        r=requests.post(url=url,json=body,headers=headers)
        print(r.json())
        assert r.status_code == 200
        assert r.json()['msg'] == "该地区名已存在"
        assert '该地区名已存在' in r.text
    def test_list(self):
        url="http://10.59.9.21/api/area/get"
        body={"wheres":"","sorts":"atype asc,sort asc","pageIndex":1,"pageSize":10}
        headers={"token":Testhelp.token,"uid":"1"}
        r=requests.post(url=url,json=body,headers=headers)
        print(r.json())
        assert r.json()['data']['list'][0]['atype'] == None
        assert '登录成功' in r.text
    def test_2page(self):
        url="http://10.59.9.21/api/area/get"
        body={"wheres":"","sorts":"atype asc,sort asc","pageIndex":2,"pageSize":10}
        headers = {"token": Testhelp.token, "uid": "1"}
        r=requests.post(url=url,json=body,headers=headers)
        print(r.json())
        # assert r.status_code == 200
        # assert r.json()['msg'] == '登录成功'
        # assert '登录成功' in r.text
    def test_add_false(self):
        url="http://10.59.9.21/api/area/add"
        body={"atype":2,"name":"1","sort":""}
        headers = {"token": Testhelp.token, "uid": "1"}
        r = requests.post(url=url, json=body, headers=headers)
        # assert r.status_code == 200
        # assert r.json()['msg'] == '服务端错误'
        # assert '服务端错误' in r.text
        print(r.json())
    def test_add_false2(self):
        url="http://10.59.9.21/api/area/add"
        body={"atype":2,"name":"","sort":"2"}
        headers = {"token": Testhelp.token, "uid": "1"}
        r = requests.post(url=url, json=body, headers=headers)
        print(r.json())
        # assert r.status_code == 200
        # assert r.json()['msg'] == '该地区名已存在'
        # assert '该地区名已存在' in r.text
    def test_add_false3(self):
        url="http://10.59.9.21/api/area/add"
        body={"atype":2,"name":"","sort":""}
        headers = {"token": Testhelp.token, "uid": "1"}
        r = requests.post(url=url, json=body, headers=headers)
        print(r.json())
        # assert r.status_code == 200
        # assert r.json()['msg'] == '服务端错误'
        # assert '服务端错误' in r.text





